package com.un.ebs.core.security;

import com.un.ebs.userdetails.domain.SecurityUser;
import com.un.ebs.userdetails.dto.UserDetailsDto;
import com.un.ebs.userdetails.service.SecurityUserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @email liubocs@163.com
 * @date 2020/6/10 16:43
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private SecurityUserDetailsService securityUserDetailsService;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        SecurityUser securityUser = securityUserDetailsService.queryByUserName(s);
        if (securityUser == null) {
            throw new UsernameNotFoundException("用户名不正确。");
        }
        return new UserDetailsDto(securityUser);
    }
}
